{extend name="../index/public/mlay" /}
{block name="title"}收货地址{/block}
{block name="style"}
<style>
	.orange .weui-btn_primary {
		background-color: #d1ab31 !important;
	}
</style>
{/block}
{block name="header"}
{include file="public/header" /}
{/block}
{block name="container"}
{eq name="$user.auth" value="0"}
<div class="line-div bgn"></div>
<div class="weui-msg">
	 <div class="weui-msg__icon-area"><i class="weui-icon-warn weui-icon_msg"></i></div>
	<div class="weui-msg__text-area">
		<h2 class="weui-msg__title">暂未获得权限</h2>
		<p class="weui-msg__desc">请实名认证后，联系管理员开通</p>
	</div>
</div>
{else/}
<div class="line-div bgn"></div>
<div class="weui-form" style="padding: 0;">
	<div class="weui-form__control-area">
		<div class="weui-cells__group weui-cells__group_form">
			<div class="weui-cells__title">{$Request.param.tips|default="基本信息"}</div>
			<div class="weui-cells weui-cells_form">
				<div class="weui-cell weui-cell_readonly">
					<div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
					<div class="weui-cell__bd">
						<input class="weui-input" name="realname" placeholder="填写本人真实姓名"
							value="{$user.realname|default=''}" disabled="disabled">
					</div>
				</div>
				<div class="weui-cell weui-cell_readonly mobile">
					<div class="weui-cell__hd"><label class="weui-label">电话</label></div>
					<div class="weui-cell__bd">
						<input id="mobile" class="weui-input" name="mobile" placeholder="填写本人的电话号码" type="number"
							pattern="[0-9]*" value="{$user.mobile|default=''}" disabled="disabled">
					</div>
				</div>
				<div class="weui-cells__title">地址详情</div>
				<div class="weui-cell" id="get_city">
					<div class="weui-cell__hd"><label class="weui-label">选择城市</label></div>
					<div class="weui-cell__bd">
						<input class="weui-input" name="fulladdress" placeholder="省 - 市 - 区" type="text"
							value="{$info.fulladdress|default=''}">
						<input type="hidden" name="province" value="{$vip.province|default=''}">
						<input type="hidden" name="city" value="{$vip.city|default=''}">
						<input type="hidden" name="country" value="{$vip.country|default=''}">
					</div>
				</div>
				<div class="weui-cell">
					<div class="weui-cell__hd"><label class="weui-label">详细地址</label></div>
					<div class="weui-cell__bd">
						<input class="weui-input" name="address" placeholder="请填写省市区后的地址" type="text"
							value="{$vip.address|default=''}">
					</div>
				</div>
				<div class="weui-cell">
					<div class="weui-cell__hd"><label class="weui-label">邮政编码</label></div>
					<div class="weui-cell__bd">
						<input class="weui-input" name="postalcode" placeholder="邮政编码" type="text"
							value="{$vip.postalcode|default=''}">
						{:token_field()}
					</div>
				</div>
			</div>
		</div>
	</div>
	{eq name="$vip.edit_address" value="1"}
	<div class="weui-form__opr-area">
		<a class="weui-btn weui-btn_primary bgv" href="javascript:" id="to-post">提交</a>
	</div>
	<div class="weui-form__tips-area">
		<p class="weui-form__tips">
			收货地址信息是系统所需，请准确填写!
		</p>
	</div>
	{else/}
	<div class="weui-form__tips-area">
		<p class="weui-form__tips">
			禁止修改，如需修改请联系管理员!
		</p>
	</div>
	{/eq}
</div>
{/eq}
{/block}
{block name="copyright"}{/block}
{block name="script"}
<script>
	$(document).ready(function() {
		$("#to-post").on("click", function() {
			var data = {
				postalcode: $("input[name='postalcode']").val(),
				province: $("input[name='province']").val(),
				city: $("input[name='city']").val(),
				address: $("input[name='address']").val(),
				country: $("input[name='country']").val(),
				__token__: $("input[name='__token__']").val(),
			}
			$.post('', data, function(res) {
				if (res.code == 0) {
					weui.topTips(res.msg, {
						className: 'warning'
					});
				} else {
					weui.topTips(res.msg, {
						className: 'success'
					});
					var golink = function() {
						// window.location.href = res.url;
						history.go(-1);
					}
					setTimeout(golink, 500);
				}
			})
		})
		$("#get_city").on("click", function(){
			weui.picker({$area|json_encode|raw}, {
			   className: 'orange',
			   container: 'body',
			   defaultValue: ["{$vip.province|default='0'}", "{$vip.city|default='0'}", "{$vip.country|default='0'}"],
			   onChange: function (result) {
				   // console.log(result)
			   },
			   onConfirm: function (result) {
			       // console.log(result)
				   $("input[name='province']").val(result[0].value);
				   $("input[name='city']").val(result[1].value);
				   var text = result[0].label + result[1].label;
				   if (result[2]) {
					   $("input[name='country']").val(result[2].value);
					   text +=result[2].label;
				   }
				   $("input[name='fulladdress']").val(text)
			   },
			   depth: 3,
			   id: 'doubleLinePicker',
			   title: '选择城市',
			});
		})
	})
</script>
{/block}
